Conditions | 4 |
Total Lines | 125 |
Code Lines | 110 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from 'react'; |
||
247 | |||
248 | renderChild() { |
||
249 | return ( |
||
250 | <ValidationForm ref={(f) => { this.form = f; }}> |
||
251 | {this.props.mode === 'modify' && |
||
252 | <FormGroup controlId="id"> |
||
253 | <ControlLabel>ID</ControlLabel> |
||
254 | <FormControl.Static>{this.state.data.id}</FormControl.Static> |
||
255 | </FormGroup> |
||
256 | } |
||
257 | <FormGroup controlId="isActivated"> |
||
258 | <ControlLabel> |
||
259 | 알림 활성화 <sup>✱</sup> |
||
260 | </ControlLabel> |
||
261 | <ButtonToolbar> |
||
262 | <ToggleButtonGroup |
||
263 | type="radio" |
||
264 | name="isActivated" |
||
265 | value={this.state.data.isActivated ? 2 : 1} |
||
266 | defaultValue={1} |
||
267 | onChange={() => { /* 버그로 인해 호출되지 않으므로 사용하지 않음 */ }} |
||
268 | > |
||
269 | <ToggleButton value={2} onClick={() => this.setDataField({ isActivated: true })}>ON</ToggleButton> |
||
270 | <ToggleButton value={1} onClick={() => this.setDataField({ isActivated: false })}>OFF</ToggleButton> |
||
271 | </ToggleButtonGroup> |
||
272 | </ButtonToolbar> |
||
273 | </FormGroup> |
||
274 | <ValidationField controlId="type" label="알림 타입" required validate={() => this.validateField('type')}> |
||
275 | <FormControl |
||
276 | componentClass={SimpleSelect} |
||
277 | value={this.state.data.type} |
||
278 | onValueChange={type => this.onStatusTypesChanged(type)} |
||
279 | placeholder="알림 타입을 선택하세요" |
||
280 | options={this.props.options.statusTypes} |
||
281 | /> |
||
282 | </ValidationField> |
||
283 | <ValidationField |
||
284 | controlId="dateRange" |
||
285 | label="알림 시작 / 종료 일시" |
||
286 | required |
||
287 | validate={() => this.validateField('dateRange')} |
||
288 | > |
||
289 | <FormControl |
||
290 | componentClass={DateRangeSelector} |
||
291 | value={this.state.data.dateRange} |
||
292 | onChange={dateRange => this.setDataField({ dateRange })} |
||
293 | /> |
||
294 | </ValidationField> |
||
295 | <Row> |
||
296 | <HelpBlock>시작/종료 일시의 기본값은 현재부터 2시간으로 설정되어 있습니다.</HelpBlock> |
||
297 | </Row> |
||
298 | <ValidationField |
||
299 | controlId="content" |
||
300 | required |
||
301 | label="알림 내용" |
||
302 | validate={() => this.validateField('content')} |
||
303 | > |
||
304 | <FormControl |
||
305 | componentClass="input" |
||
306 | value={this.state.data.title} |
||
307 | onChange={e => this.setDataField({ title: e.target.value })} |
||
308 | placeholder="제목" |
||
309 | /> |
||
310 | <FormControl |
||
311 | componentClass={RichEditor} |
||
312 | inputRef={(e) => { this.contentEditor = e; }} |
||
313 | value={this.state.data.contents} |
||
314 | onChange={contents => this.setDataField({ contents })} |
||
315 | placeholder="내용" |
||
316 | /> |
||
317 | </ValidationField> |
||
318 | <ValidationField |
||
319 | controlId="deviceTypes" |
||
320 | label="타겟 디바이스 타입" |
||
321 | required |
||
322 | validate={() => this.validateField('deviceTypes')} |
||
323 | > |
||
324 | <FormControl |
||
325 | componentClass={MultiSelect} |
||
326 | values={this.state.data.deviceTypes} |
||
327 | onValuesChange={deviceTypes => this.onDeviceTypesChanged(deviceTypes)} |
||
328 | placeholder="디바이스 타입을 선택하세요" |
||
329 | options={this.props.options.deviceTypes} |
||
330 | renderValue={item => ( |
||
331 | <div className="simple-value item-removable"> |
||
332 | <span>{item.label}</span> |
||
333 | <button |
||
334 | onClick={() => this.onDeviceTypesChanged(this.state.data.deviceTypes.filter(t => t.value !== item.value))} |
||
335 | >x</button> |
||
336 | </div> |
||
337 | )} |
||
338 | /> |
||
339 | </ValidationField> |
||
340 | <Row> |
||
341 | <HelpBlock>타겟 디바이스를 여러 개 선택할 경우 타겟 디바이스 버전과 앱 버전을 설정할 수 없습니다.</HelpBlock> |
||
342 | </Row> |
||
343 | <ValidationField |
||
344 | controlId="deviceVersion" |
||
345 | style={{ display: this.state.versionSelectorDisabled ? 'none' : 'block' }} |
||
346 | label="타겟 디바이스 버전" |
||
347 | required |
||
348 | validate={() => this.validateField('deviceVersion')} |
||
349 | > |
||
350 | <FormControl |
||
351 | componentClass={VersionSelector} |
||
352 | values={this.state.data.deviceSemVersion} |
||
353 | onChange={(deviceSemVersion => this.setDataField({ deviceSemVersion }))} |
||
354 | disabled={this.state.versionSelectorDisabled} |
||
355 | /> |
||
356 | </ValidationField> |
||
357 | <ValidationField |
||
358 | controlId="appVersion" |
||
359 | style={{ display: this.state.versionSelectorDisabled ? 'none' : 'block' }} |
||
360 | label="앱 버전" |
||
361 | required |
||
362 | validate={() => this.validateField('appVersion')} |
||
363 | > |
||
364 | <FormControl |
||
365 | componentClass={VersionSelector} |
||
366 | values={this.state.data.appSemVersion} |
||
367 | onChange={(appSemVersion => this.setDataField({ appSemVersion }))} |
||
368 | disabled={this.state.versionSelectorDisabled} |
||
369 | /> |
||
370 | </ValidationField> |
||
371 | </ValidationForm> |
||
372 | ); |
||
401 |